package com.jbookstore.dao.daoImpl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

import com.jbookstore.dao.CategoryDao;
import com.jbookstore.dto.CategoryDto;

public class CategoryDaoImpl implements CategoryDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public List<CategoryDto> selectCategoryList() {

		String sql = "select * from category";

		List<CategoryDto> categoryList = jdbcTemplate.query(sql,
				new Object[] {}, new RowMapper<CategoryDto>() {
					public CategoryDto mapRow(ResultSet rs, int rowNum)
							throws SQLException {
						CategoryDto category = new CategoryDto();
						category.setCategoryId(rs.getString("category_id"));
						category.setCategoryNm(rs.getString("category_nm"));
						category.setSort(rs.getInt("sort"));
						return category;
					}
				});

		return categoryList;
	}
}
